home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
- *
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
- /*
- * Portions Copyright (c) 2001 Louis Gerbarg. All rights reserved
- *
- * This is evil nasty unreliable code. Do not use this.
- * Why are you still reading this !?!
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- * Fine, I am not going to win. You have been warned. Don't come to me when your system
- * turns into a steaming pile of melted poly-carbonate.
- */
-
- #include <mach/mach_types.h>
-
- #include "PatchIt.h"
- #include <UserNotification/KUNCUserNotifications.h>
- #include <kern/lock.h>
- #include <kern/task.h>
- #include <kern/thread.h>
- #include <stdarg.h>
- #include <string.h>
- //#include <kern/printf.h>
- #include <sys/malloc.h>
-
-
- extern int return_on_panic;
-
- extern void
- panic(const char *str, ...);
-
- void
- my_panic(PatchPtr patch, ...);
-
- static char *display_string;
- static char *display_string_internal;
-
- kern_return_t DSPanic_start (kmod_info_t * ki, void * d)
- {
- InitPatchIt();
- PatchIt(panic, my_panic);
-
- //Oh boy, lets waste 8k of kernel ram cause I am lazy.
-
- MALLOC(display_string, char *,PAGE_SIZE, M_TEMP, M_WAITOK);
- MALLOC(display_string_internal, char *,PAGE_SIZE, M_TEMP, M_WAITOK);
-
- //Vestigial, but just in case....
-
- return_on_panic = 1;
-
- //Sanity checking, I would only need that if I were sane.
-
- return KERN_SUCCESS;
- }
-
- kern_return_t DSPanic_stop (kmod_info_t * ki, void * d)
- {
- return_on_panic = 0;
-
- //I suppose I should free that...
-
- FREE(display_string, M_TEMP);
- FREE(display_string_internal, M_TEMP);
-
-
-
- UnInitPatchIt();
-
- //I was not sane then, and I am not sane now.
-
- return KERN_SUCCESS;
- }
-
- //stolen blantantly from the kernel sources.
-
- static char *paniccopy_str;
-
- static void
- paniccopybyte(
- char byte)
- {
- *paniccopy_str++ = byte;
- *paniccopy_str = '\0';
- }
-
- //I have no idea what header this is in, and I am not looking at this hour.
-
- extern void
- _doprnt(register const char *fmt, va_list *argp,void (*putc)(char),int radix);
-
- extern mutex_t sprintf_lock;
-
- //This is the good part.
-
- void my_panic(PatchPtr patch, ...)
- {
-
- va_list listp;
- char *fmt;
-
- fmt = (char *)patch->arg0Save;
- strcpy(display_string_internal, "The kernel \"xnu\" has unexpectedly panicked with error \"\0");
- strcat(display_string_internal, fmt);
- strcat(display_string_internal, ".\" Please save all active work and restart the machine.\0");
-
- va_start(listp, patch);
- paniccopy_str = display_string;
- _doprnt(display_string_internal, &listp, paniccopybyte, 16);
- va_end(listp);
-
- /* Now I am going to trigger a userspace code path after the panic
- * There are about 12 bazillion things that can go wrong here.
- * And that doesn't include if any of the code path is paged out ;-)
- */
-
- KUNCUserNotificationDisplayNotice( 600, 0, 0, 0, 0,
- "DSPanic", display_string , "Okay");
-
- /* I should call through to panic, but it has problems.
- * ...
- * Oh, and I would need to forge the stack frame. Fuck it, I am done.
- */
- }